package com.project.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.project.bean.ClassBean;
import com.project.service.ClassService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("class")
public class ClassController {

    @Resource
    private ClassService classService;

    //显示所有信息
    @RequestMapping("findAllClass")
    @ResponseBody
    public IPage<ClassBean> findAllClass(@RequestParam(value = "pageNo", defaultValue = "1") int pageNo,
                                         @RequestParam(value = "pageSize", defaultValue = "3") int pageSize) {
        return classService.findAllClass(pageNo, pageSize);
    }


    //添加小班
    @RequestMapping("addClass")
    @ResponseBody
    public String addClass(ClassBean classBean,int areaId) {
        classService.addClass(classBean,areaId);
        return "ok";
    }

    //查看小班信息
    @RequestMapping("findId")
    @ResponseBody
    public ClassBean FindId(int classId) {
        return classService.findId(classId);
    }

    @RequestMapping("findId2")
    @ResponseBody
    public ClassBean FindId2(int classId) {
        return classService.findId(classId);
    }


    //修改小班信息
    @RequestMapping("updateClass")
    @ResponseBody
    public String updateClass(int classId, String classMan, String classMnaTel) {
        classService.updateClass(classId, classMan, classMnaTel);
        return "ok";
    }

    //模糊查询
    @RequestMapping("findName")
    @ResponseBody
    public IPage<ClassBean> FindName(@RequestParam(value = "pageNo", defaultValue = "1") int pageNo,
                                     @RequestParam(value = "pageSize", defaultValue = "3") int pageSize,
                                     String className, String area) {
        return classService.findName(pageNo,pageSize,className, area);
    }


    @RequestMapping("findClass")
    @ResponseBody
    public ClassBean findClass(int areaId) {
        return classService.findClass(areaId);
    }


    @RequestMapping("showClassName")
    @ResponseBody
    public List<ClassBean> showClassName(){
        return classService.showClassName();
    }



}
